package com.foreverwin.mes.meapi.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.foreverwin.mes.core.base.FrontPage;
import com.foreverwin.mes.meapi.mapper.ResrceMapper;
import com.foreverwin.mes.meapi.model.Operation;
import com.foreverwin.mes.meapi.model.Resrce;
import com.foreverwin.mes.meapi.service.ResrceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Syngna
 * @since 2020-01-13
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ResrceServiceImpl extends ServiceImpl<ResrceMapper, Resrce> implements ResrceService {


    @Autowired
    private ResrceMapper resrceMapper;

    @Override
    public Page<Resrce> selectPage(FrontPage<Resrce> frontPage, Resrce resrce) {
        EntityWrapper<Resrce> queryWrapper = new EntityWrapper<>();
        queryWrapper.setEntity(resrce);
        return super.selectPage(frontPage.getPagePlus(), queryWrapper);
    }

    @Override
    public List<Resrce> selectList(Resrce resrce) {
        EntityWrapper<Resrce> queryWrapper = new EntityWrapper<>();
        queryWrapper.setEntity(resrce);
        return super.selectList(queryWrapper);
    }

    @Override
    public Resrce selectByCode(String site, String resrce) {
        Resrce param = new Resrce();
        param.setSite(site);
        param.setResrce(resrce);
        List<Resrce> resrceList = this.selectList(param);
        return resrceList != null && resrceList.size() > 0 ? resrceList.get(0) : null;
    }

    @Override
    public Operation selectOperation(String site, String resource) {
        List<Operation> operations = resrceMapper.selectOperation( site, resource );
        if( operations.isEmpty() ){
            return null;
        }else{
            return operations.get( 0 );
        }
    }

    @Override
    public List<Resrce> selectEnhanceList(Resrce resrce) {
        return resrceMapper.selectEnhanceList(resrce);
    }

    @Override
    public List<Resrce> listByResourceType(String site, String resourceType) {
        return resrceMapper.selectByResourceType(site, resourceType);
    }


}